package com.jwgf.faultnavigation;

import android.view.View;

import com.jwgf.adapter.ItemViewDelegate;
import com.jwgf.adapter.RecyclerViewHolder;
import com.jwgf.common.AppContext;
import com.jwgf.common.Utility;
import com.jwgf.smarowindingmachine_unity.R;

import org.greenrobot.eventbus.EventBus;

public class FaultNavigationDetailDelegate implements ItemViewDelegate {
    @Override
    public int getItemViewLayoutId() {
        return R.layout.fault_navigation_step;
    }

    @Override
    public boolean isForViewType(Object item, int position) {
        return item instanceof FaultNavigationAttr.NavigationStep;
    }

    @Override
    public void bindView(RecyclerViewHolder holder, Object o, int position) {
        final FaultNavigationAttr.NavigationStep step = (FaultNavigationAttr.NavigationStep) o;
        holder.setText(R.id.step, String.valueOf(position + 1));
        for (int i = 0; i < step.imgs.length; ++i) {
            int id = Utility.ResourcesUtils.getId(AppContext.getInstance(), "img" + (i + 1));
            holder.setImageResource(id, step.imgs[i]);
            holder.getView(id).setVisibility(View.VISIBLE);
            final int finalI = i;
            holder.setOnClickListener(id, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventBus.getDefault().post(new PictureId(step.imgs[finalI]));
                }
            });
        }
        holder.setText(R.id.detail, step.details);

    }

}
